#ifndef __SCANNER_H__
#define __SCANNER_H__

#include "common.h"
#include "LinkedList.h"
#include "Token.h"
#include "BinTree.h"

class SourceLine
{
private:
	LinkedList<Token*>* tokens;
	string source;

public:
	SourceLine(string source, LinkedList<Token*>* tokens);

	string getSourceLine() const;
	LinkedList<Token*>* getTokens() const;
};

class IdentifierGroup
{
private:
	string name;
	LinkedList<int> lines;

public:
	IdentifierGroup(string name, int first_line)
	{
		this->name = name;
		this->lines.append(first_line);
	}

	bool operator >(IdentifierGroup* rhs)
	{
		return name > rhs->name;
	}

	bool operator ==(IdentifierGroup* rhs)
	{
		return name == rhs->name;
	}

	void appendLineNumber(int line)
	{
		lines.append(line);
	}

	LinkedList<int>* getLineNumbers()
	{
		return &lines;
	}

	string getIdentifierName()
	{
		return name;
	}
};

class Scanner
{
private:
	string source_file;
	LinkedList<SourceLine*> lines;
	BinTree<IdentifierGroup*>* identifiers;

	static LinkedList<TokenExtractor*>* extractors;

	void initialize();

public:
	Scanner(string& file_name);

	const LinkedList<SourceLine*>* getLines() const;
	string getSourceFileName() const;
	BinTree<IdentifierGroup*>* getIdentifiers() const;
};

#endif